/*
 * @Author: 0x9DEFA478
 * @Date: 2025-06-22 17:58:07
 * @LastEditTime: 2025-09-22 23:40:22
 * @LastEditors: 0x9DEFA478
 * @Description: 
 * 
 */
#ifndef hH_Path_HPP_
#define hH_Path_HPP_
#include <string>
#include <vector>


namespace H{


  class Path{

    public:
      static const Path Empty;

#if defined(__linux__)
      static constexpr const char* SplitCharList="/";
#elif defined(_WIN32)
      static constexpr const char* SplitCharList="/\\";
#endif

    public:

      Path();
      Path(const std::string& path,const std::string& splitCharList=SplitCharList){construct(path.c_str(),splitCharList);}
      Path(const char* path,const std::string& splitCharList=SplitCharList){construct(path,splitCharList);}
      ~Path();

      Path(const Path& path);
      Path(Path&& path);

      Path& operator=(const Path& path);
      Path& operator=(Path&& path);

      Path& operator+=(const Path& path);
      Path operator+(const Path& path)const;
      int compare(const Path& path)const;
      bool operator==(const Path& path)const{return compare(path)==0;};
      bool operator>=(const Path& path)const{return compare(path)>=0;};
      bool operator>(const Path& path)const{return compare(path)>0;};
      bool operator<=(const Path& path)const{return compare(path)<=0;}
      bool operator<(const Path& path)const{return compare(path)<0;}

      bool IsParentOrEqual(const Path& path)const;
      bool IsRelative()const;
      bool IsSuffix(const std::string suffix,bool CaseInsensitive=false)const;

      std::string String(const std::string& splitText="/",const std::string& local=".")const;
      std::string Name()const;

      /**
       * @brief 去除冗余的相对路径标识符
       *        开头的相对路径会被整理, 仅保留必要的
       * @param DiscardEmpty 是否去除空(0长度)文件夹名/文件名
       * @param local 相对当前路径名
       * @param parent 相对父路径名
       * @return noEdit
       */
      Path DiscardRelative(bool DiscardEmpty=true,const std::string& local=".",const std::string& parent="..")const;
      Path ToRelative()const;

    private:
      void construct(const char* path,const std::string& splitCharList);

    private:
      std::vector<std::string> path;//path[0]为0长度字符串代表根目录 /
  };

}


#endif //hH_Path_HPP_
